package com.sangcomz.fishbun;

import com.sangcomz.fishbun.adapter.image.ImageAdapter;
import com.sangcomz.fishbun.util.UiUtil;
import ohos.agp.colors.RgbPalette;
import ohos.agp.components.element.Element;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;
import ohos.utils.net.Uri;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;

/**
 * Created by seokwon.jeong on 04/01/2018.
 */
public final class Fishton {

    private static volatile Fishton fishton;

    private Fishton() {
        initValue();
    }

    public static Fishton getInstance() {
        synchronized (Fishton.class) {
            if (fishton == null) {
                synchronized (Fishton.class) {
                    fishton = new Fishton();
                }
            }
        }
        return fishton;
    }

    public ImageAdapter imageAdapter;
    public List<Uri> currentPickerImageList = emptyList();

    //BaseParams
    public int maxCount = 0;
    public int minCount = 0;
    public List<MimeType> exceptMimeTypeList = emptyList();
    public ArrayList<Uri> selectedImages = new ArrayList<>();


    //CustomizationParams
    public List<String> specifyFolderList = emptyList();
    public int photoSpanCount = 0;
    public int albumPortraitSpanCount = 0;
    public int albumLandscapeSpanCount = 0;

    public boolean isAutomaticClose = false;
    public boolean hasButtonInAlbumActivity = false;

    public int colorActionBar = 0;
    public int colorActionBarTitle = 0;
    public int colorStatusBar = 0;

    public boolean isStatusBarLight = false;
    public boolean hasCameraInPickerPage = false;

    public int albumThumbnailSize = 0;

    public String messageNothingSelected = "";
    public String messageLimitReached = "";
    public String titleAlbumAllView = "";
    public String titleActionBar = "";

    public Element drawableHomeAsUpIndicator = null;
    public Element drawableDoneButton = null;
    public Element drawableAllDoneButton = null;
    public boolean isUseAllDoneButton = false;

//    var drawableHomeAsUpIndicator:Drawable?=null
//    var drawableDoneButton:Drawable?=null
//    var drawableAllDoneButton:Drawable?=null
//    var isUseAllDoneButton:Boolean =false

    public String strDoneMenu = null;
    public String strAllDoneMenu = null;

    public int colorTextMenu = 0;

    public boolean isUseDetailView = false;

    public boolean isShowCount = false;

    public int colorSelectCircleStroke = 0;

    public boolean isStartInAllView = false;

    public void refresh() {
        initValue();
    }


    private void initValue() {
        //BaseParams
        maxCount = 10;
        minCount = 1;
        exceptMimeTypeList = emptyList();
        selectedImages = new ArrayList();

        //CustomizationParams
        specifyFolderList = emptyList();
        photoSpanCount = 4;
        albumPortraitSpanCount = 1;
        albumLandscapeSpanCount = 2;

        isAutomaticClose = false;
        hasButtonInAlbumActivity = false;

        colorActionBar = RgbPalette.parse("#3F51B5");
        colorActionBarTitle = RgbPalette.parse("#ffffff");
        colorStatusBar = RgbPalette.parse("#303F9F");

        isStatusBarLight = false;
        hasCameraInPickerPage = false;

        albumThumbnailSize = Integer.MAX_VALUE;

        drawableHomeAsUpIndicator = null;
        drawableDoneButton = null;
        drawableAllDoneButton = null;

        strDoneMenu = null;
        strAllDoneMenu = null;

        colorTextMenu = Integer.MAX_VALUE;

        isUseAllDoneButton = false;
        isUseDetailView = true;
        isShowCount = true;

        colorSelectCircleStroke = RgbPalette.parse("#c1ffffff");
        isStartInAllView = false;

        titleActionBar = "";
        messageNothingSelected = "";
        messageLimitReached = "";
        titleAlbumAllView = "";
    }

    public void setDefaultMessage(Context context) {
        if (messageNothingSelected.isEmpty()) {
            messageNothingSelected = context.getString(ResourceTable.String_msg_no_selected);
        }

        if (messageLimitReached.isEmpty()) {
            messageLimitReached = context.getString(ResourceTable.String_msg_full_image);
        }

        if (titleAlbumAllView.isEmpty()) {
            titleAlbumAllView = context.getString(ResourceTable.String_str_all_view);
        }

        if (titleActionBar.isEmpty()) {
            titleActionBar = context.getString(ResourceTable.String_album);
        }
    }

    public void setMenuTextColor() {
        if (drawableDoneButton != null
                || drawableAllDoneButton != null
                || strDoneMenu == null
                || colorTextMenu != Integer.MAX_VALUE
        ) {
            return;
        }

        //colorTextMenu = if (isStatusBarLight) Color.BLACK else
        if (isStatusBarLight) {
            colorTextMenu = Color.BLACK.getValue();
        } else {

        }
    }

    public void setDefaultDimen(Context context) throws NotExistException, WrongTypeException, IOException {
        albumThumbnailSize = 0;
        if (albumThumbnailSize == Integer.MAX_VALUE) {
            albumThumbnailSize = UiUtil.getDimension(context, ResourceTable.Integer_album_thum_size);
        } else {
            albumThumbnailSize = 0;
        }
    }
}